package com.aqie.medium.matrix;

/**
 * 861 翻转矩阵得最高分
 * 贪心算法 todo
 */
public class MatrixScore {
    public int matrixScore(int[][] A) {
        int R = A.length;
        int C = A[0].length;
        int ans = 0;

        // 通过行变换 将第一列变为1
        int[] flag = new int[R];
        for (int i = 0; i < R; i++){
            // 该行需要进行行变换
            if (A[i][0] == 0){
                flag[i] = 1;
            }
        }
        int a = 1;
        for (int j = C - 1; j >= 1; j--){
            int tmp = 0;
            for (int i = 0; i < R; i++){
               if (flag[i] == 1){
                   tmp += 1 - A[i][j];
               }else{
                   tmp += A[i][j];
               }
            }
            if (tmp <= R / 2){
                tmp = R - tmp;
            }
            ans += a * tmp;
            a = a * 2;
        }
        ans += R * a;
        return ans;
    }


    public static void main(String[] args) {
        int[][] arr = {{0,0,1,1},{1,0,1,0},{1,1,0,0}};
    }
}
